from celery import Celery
from kombu import Queue
import os

app = Celery('compute')

#只启动一个worker进程 没有并行
app.conf.worker_concurrency = 1

# 从环境变量获取Redis相关配置
_password = os.environ['REDIS_PASSWORD']
_broker_addr = os.environ['REDIS_HOST']
_port = os.environ['REDIS_PORT']

# 设在broker地址
app.conf.broker_url = f'redis://:{_password}@{_broker_addr}:{_port}/0'

# 设置该 Celery Worker 应该监听的队列
app.conf.task_queues = [
    Queue('zmm.request.queue'),
]

# 设置任务发送的目标队列
app.conf.task_routes = {
    # 假设发送的任务消息名都以 "zmm." 开头
    'zmm.*': {
        # 发往请求队列
        'queue': 'zmm.results.queue'
    },
}